package singleflight;



import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Supplier;

//代表正在进行中，或已经结束的请求
public class Call {
    //存储任务的结果
    byte[] val;
    //用于同步线程，确保只有一个线程实际执行任务
    CountDownLatch latch;

    public byte[] getVal() {
        return val;
    }

    public void setVal(byte[] val) {
        this.val = val;
    }

    //初始化 CountDownLatch，设置计数器为 1
    void lock(){
        latch=new CountDownLatch(1);
    }

    //阻塞调用线程，等待 done() 方法被调用
    void await() throws InterruptedException {
        latch.await();
    }
    void done(){
        latch.countDown();
    }
}
